import { dialog, BrowserWindow, app } from "electron";
import Update from "../services/check-update";
import { IIpcMainHandle } from "../../ipc/index";

export class IpcMainHandleClass implements IIpcMainHandle {
  private allUpdater: Update;

  constructor() {
    this.allUpdater = new Update();
  }

  AppClose: (event: Electron.IpcMainInvokeEvent) => void | Promise<void> = (
    event
  ) => {
    app.quit();
  };

  CheckUpdate: (event: Electron.IpcMainInvokeEvent) => void | Promise<void> = (
    event
  ) => {
    this.allUpdater.checkUpdate(BrowserWindow.fromWebContents(event.sender));
  };

  ConfirmUpdate: (event: Electron.IpcMainInvokeEvent) => void | Promise<void> =
    () => {
      this.allUpdater.quitAndInstall();
    };

  DownloadUpdate: (event: Electron.IpcMainInvokeEvent) => void | Promise<void> =
    () => {
      this.allUpdater.downloadUpdate();
    };
}
